package nave.android.exemplo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class SingleTouchTest extends Activity implements OnTouchListener 
{
	StringBuilder builder = new StringBuilder();
	TextView textView;
	
	PowerManager pm;
	PowerManager.WakeLock wl;
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
		filter.addAction(Intent.ACTION_SCREEN_OFF);
		BroadcastReceiver mReceiver = new BroadcastReceiver()
		{
			@Override
			public void onReceive(Context context, Intent intent) {
			}
		};
		
		registerReceiver(mReceiver, filter);
		
		pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		
		textView = new TextView(this);
		textView.setText("Touch and drag (one finger only)!");
		textView.setOnTouchListener(this);
		setContentView(textView);
	}
	
	@Override
	public boolean onTouch(View v, MotionEvent event)
	{
		builder.setLength(0);
		switch (event.getAction())
		{
			case MotionEvent.ACTION_DOWN:
				wl = pm.newWakeLock(PowerLock.SCREEN_DIM_WAKE_LOCK | 
						PowerManager.ON_AFTER_RELEASE, "My Tag");
				wl.acquire();
				wl.release();
				builder.append("down, ");
				break;
			case MotionEvent.ACTION_MOVE:
				builder.append("move, ");
				break;
			case MotionEvent.ACTION_CANCEL:
				builder.append("cancle, ");
				break;
			case MotionEvent.ACTION_UP:
				builder.append("up, ");
				break;				
		}
		builder.append(event.getX());
		builder.append(", ");
		builder.append(event.getY());
		String text = builder.toString();
		Log.d("TouchTest", text);
		textView.setText(text);
		return true;
	}
}
